package com.example.myapplication.part8;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;

import com.example.myapplication.R;

public class Part8Activity extends AppCompatActivity {

    private Switch switchControl;
    private ImageView bulbImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_part8); // 绑定布局

        // 初始化控件
        switchControl = findViewById(R.id.switchControl);
        bulbImageView = findViewById(R.id.bulbImageView);

        // 设置开关监听
        switchControl.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                // 开启灯泡
                bulbImageView.setImageResource(R.drawable.bulb_on);
            } else {
                // 关闭灯泡
                bulbImageView.setImageResource(R.drawable.bulb_off);
            }
        });
    }
}